﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using System.Web.Routing;

namespace MvcControlToolkit
{
    public static class TextBoxWatermarkExtensions
    {
        public static string TextBoxWatermark(this AjaxHelper helper, string elementId, string watermarkText)
        {
            return helper.TextBoxWatermark(elementId, watermarkText, "");
        }

        public static string TextBoxWatermark(this AjaxHelper helper, string elementId, string watermarkText, string watermarkCssClass)
        {
            RouteValueDictionary props = new RouteValueDictionary();
            props.Add("WatermarkText", watermarkText);
            props.AddIfNotDefault("WatermarkCssClass", watermarkCssClass);

            return helper.TextBoxWatermark(elementId, props);
        }

        public static string TextBoxWatermark(this AjaxHelper helper, string elementId, object properties)
        {
            StringBuilder sb = new StringBuilder();

            // Add Microsoft Ajax library   
            sb.Append(helper.MicrosoftAjaxInclude());

            // Add toolkit scripts   
            sb.Append(helper.ToolkitInclude(
                    "AjaxControlToolkit.ExtenderBase.BaseScripts.js",
                    "AjaxControlToolkit.Common.Common.js",
                    "AjaxControlToolkit.TextboxWatermark.TextboxWatermark.js"
                ));

            // Perform $create               
            sb.AppendLine(helper.Create("AjaxControlToolkit.TextBoxWatermarkBehavior", properties, elementId));

            return sb.ToString();
        }
    }
}
